package com.wasp.collector.service.chain;

import java.io.Serializable;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.wasp.collector.content.Content;
import com.wasp.collector.data.BaseModel;
import com.wasp.collector.data.RequestContext;

public abstract class AbstractHandleChain implements Serializable {
    protected static final Logger log = LoggerFactory.getLogger(AbstractHandleChain.class);

	protected Content content;
	
	public AbstractHandleChain setContent(Content content){
		this.content = content;
		return this;
	}
	protected List<? extends BaseModel> needHandleData;
	public AbstractHandleChain setNeedHandleData(List<? extends BaseModel> needHandleData){
		this.needHandleData = needHandleData;
		return this;
	}
	public RequestContext getRequestContext(){
		return content.getRequestContext();
	}
	 /**
     * 持有后继的责任对象
     */
    protected AbstractHandleChain successor;
    /**
     * 示意处理请求的方法，虽然这个示意方法是没有传入参数的
     * 但实际是可以传入参数的，根据具体需要来选择是否传递参数
     */
    protected abstract void realHandleRequest();
    
    public void handleRequest(){
    	realHandleRequest();
    	if(getSuccessor() != null) {            
            getSuccessor().handleRequest();            
        }
    }
    /**
     * 取值方法
     */
    public AbstractHandleChain getSuccessor() {
        return successor;
    }
    /**
     * 赋值方法，设置后继的责任对象
     */
    public void setSuccessor(AbstractHandleChain successor) {
        this.successor = successor;
    }
}